package com.saozinha.sistema.util;



import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	private static final SessionFactory session = buildSessionFactory();

	private static SessionFactory buildSessionFactory() {
		try {
			Configuration cfg = new Configuration();
			// Arquivo configurado com conexao
			// Nao precisa indicar o caminho, pois o arquivo esta na mesma raiz
			cfg.configure("hibernate.cfg.xml"); 
			// retorna a sessao
			return cfg.buildSessionFactory();
		} catch (Throwable e) {
			System.out.println("\n >>>> Problemas com a conexao!!\n - > " + e);
			throw new ExceptionInInitializerError();
		}
	}

	public static SessionFactory getSession(){
		return session;
	}
}
